

            <div id="content"> <!-- Content begins here -->
                
                <?php echo $this->element('admin/flash') ?>
                <div class="clear"></div>
                <h2>Permissions for groups</h2>
                <div class="clear"></div>
                <div class="permissions">
        <?php
            $groupTitles = array_values($groups);
            $groupTitles = array_merge(array('Action URL'), $groupTitles);

            $currentController = '';
            $key = 0;
            $last = count($acos);
            foreach ($acos as $id => $alias) {
                $class = '';
                
                if(substr($alias, 0, 1) == '_') {
                    $level = 1;
                    $class .= 'level-'.$level;
                    $oddOptions = array('class' => 'controller-'.$currentController);
                    $evenOptions = array('class' => 'controller-'.$currentController);
                    $alias = substr_replace($alias, '', 0, 1);
                    $admin='/';
                    if(preg_match('/admin/',$alias)){
                        str_replace('admin_','',$alias);
                        $admin='/admin/';
                    }
                    $row = array($admin.strtolower($currentController).'/'.$alias);
                    
                    
                    foreach ($groups as $groupId => $roleTitle) {
                        if ($level != 0) {
                            if ($groupId != 1) {
                                
                                if ($permissions[$id][$groupId] == 1) {
                                    $row[] = '<a title="click to remove this permission" onclick="return confirm(\'Are you sure that you want to remove this permission?\')" href="'.$html->url('/admin/users/remove_permission/'.$id.'/'.$groupId).'">'.$html->image('/img/assets/action_check.png', array('class' => 'permission-toggle', 'rel' => $id.'-'.$aros[$groupId])).'</a>';
                                } else {
                                    $row[] = '<a title="click to add this permission" onclick="return confirm(\'Are you sure that you want to add this permission?\')" href="'.$html->url('/admin/users/add_permission/'.$id.'/'.$groupId).'">'.$html->image('/img/assets/action_remove.png', array('class' => 'permission-toggle', 'rel' => $id.'-'.$aros[$groupId])).'</a>';
                                }
                            } else {
                                $row[] = $html->image('/img/assets/action_check.png', array('class' => 'permission-disabled'));
                            }
                        } else {
                            $row[] = '';
                        }
                    }
                    echo $html->tableCells(array($row), $oddOptions, $evenOptions);
                    
                } else {
                    $level = 0;
                    $class .= ' controller expand';
                    $oddOptions = array();
                    $evenOptions = array();
                    $currentController = $alias;
                    if($key) echo '</table></div></div>';
                    echo '<div>'.$html->tag('h3', $alias);
                    echo '<div><table>';
                    echo $html->tableHeaders($groupTitles);
                }
                $key++;
                if($key == $last) echo '</table></div></div>';
            }

            
        ?>
        </div>
                
                

            
        </div> <!-- END Content -->
        